//
//  StrategyViewController.m
//  Strategy
//
//  Created by Carlo Chung on 8/2/10.
//  Copyright Carlo Chung 2010. All rights reserved.
//

#import "StrategyViewController.h"
#import "InputValidator.h"
#import <UIKit/UIKit.h>
@implementation StrategyViewController


/*
 // The designated initializer. Override to perform setup that is required before the view is loaded.
 - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
 if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
 // Custom initialization
 }
 return self;
 }
 */

/*
 // Implement loadView to create a view hierarchy programmatically, without using a nib.
 - (void)loadView {
 }
 */



// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
    [super viewDidLoad];
    
    [self.view setBackgroundColor:[UIColor whiteColor]];
    
    InputValidator *numValidator = [[NumericInputValidator alloc] init];
    InputValidator *alphaValidator = [[AlphaInputValidator alloc] init];
    
    _numericTextField = [[CustomTextField alloc] initWithFrame:CGRectMake(100, 150, 200, 30)];
    [_numericTextField setPlaceholder:@"支持输入数字"];
    [_numericTextField setDelegate:self];
    [_numericTextField setBorderStyle:UITextBorderStyleRoundedRect];
    [_numericTextField.layer setBorderColor:[UIColor blackColor].CGColor];
    [_numericTextField.layer setBorderWidth:1];
    [self.view addSubview:_numericTextField];
    
    _alphaTextField = [[CustomTextField alloc] initWithFrame:CGRectMake(100, CGRectGetMaxY(_numericTextField.frame)+20, CGRectGetWidth(_numericTextField.frame), 30)];
    [_alphaTextField setPlaceholder:@"只支持输入字母"];
    [_alphaTextField setDelegate:self];
    [_alphaTextField setBorderStyle:UITextBorderStyleRoundedRect];
    [_alphaTextField.layer setBorderColor:[UIColor blackColor].CGColor];
    [_alphaTextField.layer setBorderWidth:1];
    
    [self.view addSubview:_alphaTextField];
    
    [_numericTextField setInputValidator:numValidator];
    [_alphaTextField setInputValidator:alphaValidator];

}


/*
 // Override to allow orientations other than the default portrait orientation.
 - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 // Return YES for supported orientations
 return (interfaceOrientation == UIInterfaceOrientationPortrait);
 }
 */

- (void)didReceiveMemoryWarning {
  // Releases the view if it doesn't have a superview.
  [super didReceiveMemoryWarning];
  
  // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
  // Release any retained subviews of the main view.
  // e.g. self.myOutlet = nil;
}


- (void)dealloc 
{

  
}

#pragma mark -
#pragma mark UITextFieldDelegate methods

- (void)textFieldDidEndEditing:(UITextField *)textField
{
  //if (textField == numericTextField)
  //{
  // validate [textField text] and make sure
  // the value is numeric
  //}
  //else if (textField == alphaTextField)
  //{
  // validate [textField text] and make sure
  // the value contains only letters
  //}
  
  if ([textField isKindOfClass:[CustomTextField class]])
  {
    [(CustomTextField*)textField validate];
  }
}

@end
